#include <rtthread.h>
#include <lvgl.h>

#include "benchmark/lv_demo_benchmark.h"
#include "music/lv_demo_music.h"
#include "widgets/lv_demo_widgets.h"

#define LV_THREAD_NAME "lvgl"
#define LV_THREAD_STACK_SIZE 8192
#define LV_THREAD_PRIO  20
#define LV_THREAD_TICK  10

static void lv_work(void* parameter)
{
#ifdef PKG_LVGL_USING_DEMOS
    rt_kprintf("setup demo ui ...\n");
    // lv_demo_benchmark();
    // lv_demo_music();
    lv_demo_widgets();
#endif

    while (1) {
        // handle LVGL tick
        lv_task_handler();
        rt_thread_mdelay(1);
    }
}

int lv_thread_init(void)
{
    rt_thread_t tid = rt_thread_create(LV_THREAD_NAME, lv_work, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, LV_THREAD_TICK);
    if (tid == RT_NULL) {
        rt_kprintf("create '%s' thread failed\n", LV_THREAD_NAME);
        return -1;
    }
    rt_thread_startup(tid);

    rt_kprintf("%s thread create OK!\n", LV_THREAD_NAME);
    return 0;
}
INIT_APP_EXPORT(lv_thread_init);
